package com.tudouji.d3.controller;

import com.tudouji.d3.domain.D3AftersalesVo;
import com.tudouji.d3.domain.D3OrderVo;
import com.tudouji.d3.domain.ResponseBack;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.project.d3.domain.D3Order;
import com.tudouji.project.d3.service.ID3AftersalesService;
import com.tudouji.project.d3.service.ID3OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * D3回调接口
 */
@Slf4j
@RestController
@RequestMapping("/d3/callback")
public class CallBackController {

    @Autowired
    private ID3OrderService id3OrderService;
    @Autowired
    private ID3AftersalesService id3AftersalesService;
    /**
     * 插入订单、明细；查询商品信息是否为空，为空插入；
     * ***需要商品维护功能，关联sp_id
     * ***商铺维护添加关联供应商即可，或者也可以同商品功能一样，判断有无后插入
     * @return
     */
    @PostMapping("orders/insert")
    public ResponseBack insertOrder(@RequestBody D3OrderVo d3Order){
        log.info("/d3/callback/orders/insert: " + d3Order.getContent().toString());
        return id3OrderService.insertOrder(d3Order.getContent());
    }

    @PostMapping("orders/update")
    public ResponseBack updateOrder(@RequestBody D3OrderVo d3Order){
        log.info("/d3/callback/orders/update: " + d3Order.getContent().toString());
        return id3OrderService.updateOrder(d3Order.getContent());
    }
    /**
     * 售后订单
     * @return
     */
    @PostMapping("orders/after/insert")
    public ResponseBack insertAfterOrder(@RequestBody D3AftersalesVo d3AftersalesVo){
        log.info("/d3/callback/Afterorders/insert: " + d3AftersalesVo.getContent().toString());
        return id3AftersalesService.insertAfterOrder(d3AftersalesVo.getContent());
    }

    @PostMapping("orders/after/update")
    public ResponseBack updateAfterOrder(@RequestBody D3AftersalesVo d3AftersalesVo){
        log.info("/d3/callback/Afterorders/update: " + d3AftersalesVo.getContent().toString());
        return id3AftersalesService.updateAfterOrder(d3AftersalesVo.getContent());
    }
}
